<?php

require_once BaseUtil::getModulePath ( "base" ) . '/forms/BaseForm.php';
require_once BaseUtil::getModulePath ( "base" ) . '/validate/Unique.php';
require_once BaseUtil::getModulePath ( "metadata" ) . '/constants/MetadataConstant.php';

class SetForm extends BaseForm {
	
	public function __construct($data=array()) {
		
		parent::__construct ();
		
		$this->setAction ( HttpUtil::getUrl ( "set", "subaddset" ) );
		//element code
		$id = new Zend_Form_Element_Hidden ( "id" );
		
		$validUniqueCode = new MyValid_Unique ( );
		$validUniqueCode->setFetchAttr('metadata_sets', 'title');
		
        if(!empty($data)){
       		 $validUniqueCode->setId($data['id']);
        }
           
        
		//element title
		$title = new Zend_Form_Element_Text ( "title" );
		$title->setLabel ( $this->translate->_ ( 'title' ) );
		$title->addFilter ( "StringTrim" );
		$title->setRequired ( true );
		$title->addValidator($validUniqueCode);
		
		//element long title
		$tag = new Zend_Form_Element_Text ( "tag" );
		$tag->setLabel ( $this->translate->_ ( 'tag' ) );
		$tag->addFilter ( "StringTrim" );
		$tag->setRequired ( true );
		//element input type
		$defaultChequeRule = new Zend_Form_Element_Select ( 'default_cheque_rule' );
		$defaultChequeRule->setLabel ( $this->translate->_ ( 'defaultChequeRule' ) );
		$defaultChequeRule->setMultiOptions ( MetadataConstant::getDefaultChequeRuleList() );
		//element input type
		$defaultPriceRule = new Zend_Form_Element_Select ( 'default_price_rule' );
		$defaultPriceRule->setLabel ( $this->translate->_ ( 'defaultPriceRule' ) );
		$defaultPriceRule->setMultiOptions ( MetadataConstant::getDefaultPriceRuleList () );
		//element input type
		$defaultShipRule = new Zend_Form_Element_Select ( 'default_ship_rule' );
		$defaultShipRule->setLabel ( $this->translate->_ ( 'defaultShipRule' ) );
		$defaultShipRule->setMultiOptions ( MetadataConstant::getDefaultShipRuleList () );
		//element input type
		$defaultRelatedRule = new Zend_Form_Element_Select ( 'default_related_rule' );
		$defaultRelatedRule->setLabel ( $this->translate->_ ( 'defaultRelatedRule' ) );
		$defaultRelatedRule->setMultiOptions ( MetadataConstant::getDefaultRelatedRuleList () );
		
		//in_basic_search
		$status = new Zend_Form_Element_Radio ( "is_delete" );
		$status->setLabel ( $this->translate->_ ( 'status' ) );
		$status->setMultiOptions ( array ("0" => $this->translate->_ ( 'noLabel' ), "1" => $this->translate->_ ( 'yesLabel' ) ) );
		
		if(!empty($data)){
			$id->setValue($data['id']);
			$title->setValue($data['title']);
			$tag->setValue($data['tag']);
			$defaultChequeRule->setValue($data['default_cheque_rule']);
			$defaultPriceRule->setValue($data['default_price_rule']);
			$defaultShipRule->setValue($data['default_ship_rule']);
			$defaultRelatedRule->setValue($data['default_related_rule']);
			$this->setAction ( HttpUtil::getUrl ( "set", "subeditset" ) );
			
		}
		
		$this->addElements ( array ($id, $title, $tag, $defaultChequeRule, $defaultPriceRule, $defaultShipRule, $defaultRelatedRule,$status  ) );
		
		$this->setElementDecorators ( array ('ViewHelper', array (array ('div' => 'HtmlTag' ), array ('tag' => 'div', "class" => "form_element" ) ) ) );
	}
}